package cn.itcast.listener;


import cn.itcast.common.utils.MailUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.util.Map;


public class MailMessageListener implements MessageListener {

	//消息对象，message
	public void onMessage(Message message) {
		byte[] body = message.getBody();
		Map map = JSON.parseObject(body, Map.class);
		//key = abc  value:"abc"
		//map.forEach((key,value)-> System.out.println(key+"=="+value));
		String to = (String)map.get("to");
		String subject = (String)map.get("subject");
		String content = (String)map.get("content");
		try {
			MailUtil.sendMsg(to,subject,content);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
